package sketch.instrumenter;

import java.util.List;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;

import sketch.ast.ASTUtils;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class SourceInstrumenterTest extends TestCase {
	
	public static Test suite() {
		return new TestSuite(SourceInstrumenterTest.class);
	}
	
	public void testGetOunits() {
		String filePath = "./testfiles/sketch/instrumenter/SampleCodeAfterRemovingParenthesis.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		List<MethodDeclaration> methods = ASTUtils.getMethodsWithAnnotation(unit, "sketch.ounit.OUnit");
		assertEquals(1, methods.size());
	}
	
	public void testSourceInstrumentation() {
		String filePath = "./testfiles/sketch/instrumenter/SampleCodeAfterRemovingParenthesis.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		SourceCodeInstrumentingVisitor visitor = new SourceCodeInstrumentingVisitor(unit);
		visitor.visit(unit);
		
		System.out.println("after instrumentation: ");
		System.out.println(unit);
	}
	
	public void testSourceInstrumentationForTryCatch() {
		String filePath = "./testfiles/sketch/instrumenter/ReWriteRepetitiveUnitTests.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		SourceCodeInstrumentingVisitor visitor = new SourceCodeInstrumentingVisitor(unit);
		visitor.visit(unit);
		
		System.out.println("after instrumenting try catch: ");
		System.out.println(unit);
	}
}
